//$(function () {
var namespace = joint.shapes;

var graph = new joint.dia.Graph({}, { cellNamespace: namespace });

var paper = new joint.dia.Paper({
  el: document.getElementById("canvas"),
  model: graph,
  width: 600,
  height: 600,
  gridSize: 5,
  drawGrid: true,
  cellViewNamespace: namespace,
});

paper.on({
  "blank:pointerdown": function (evt, x, y) {
    var link = new joint.dia.Link();
    link.set("source", { x: x, y: y });
    link.set("target", { x: x, y: y });
    link.addTo(this.model);
    evt.data = { link: link, x: x, y: y };
  },
  "blank:pointermove": function (evt, x, y) {
    evt.data.link.set("target", { x: x, y: y });
  },
  "blank:pointerup": function (evt) {
    var target = evt.data.link.get("target");
    if (evt.data.x === target.x && evt.data.y === target.y) {
      // remove zero-length links
      evt.data.link.remove();
    }
  },
});
//});
